package com.fxust.dialog;

import com.fxust.common.PropertiesHandler;
import com.fxust.utils.FileUtils;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;

/**
 * @auto johnking
 * @create 2017-12-17 上午11:37
 **/
public class VersionConfigDialog extends BaseDialog {

    /**
     * 序列化ID
     */
    private static final long serialVersionUID = 1628225764473281514L;

    /**
     * 界面控件声明
     */
    private final JPanel versionPanel = new JPanel();
    private JLabel versionLb;
    private JLabel autherLb;
    private JLabel dateLb;

    /**
     *
     * 创建一个新的实例VersionConfigDialog.
     *
     * @param frame
     * @param title
     */
    public VersionConfigDialog(Frame frame, String title) {
        super(frame, title);

        setBounds(100, 100, 260, 200);
        getContentPane().setLayout(new BorderLayout());

        versionPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        versionPanel.setBackground(Color.WHITE);
        versionPanel.setLayout(null);
        getContentPane().add(versionPanel, BorderLayout.CENTER);
        {
            JLabel versionNumLabel = new JLabel("版本号:");
            versionNumLabel.setBounds(10, 40, 65, 15);
            versionNumLabel.setHorizontalAlignment(SwingConstants.RIGHT);
            versionPanel.add(versionNumLabel);

            JLabel authLabel = new JLabel("版本作者:");
            authLabel.setBounds(10, 70, 65, 15);
            authLabel.setHorizontalAlignment(SwingConstants.RIGHT);
            versionPanel.add(authLabel);

            JLabel dateLabel = new JLabel("发布日期:");
            dateLabel.setBounds(10, 100, 65, 15);
            dateLabel.setHorizontalAlignment(SwingConstants.RIGHT);
            versionPanel.add(dateLabel);
        }
        {
            versionLb = new JLabel("xxx");
            versionLb.setBounds(80, 40, 150, 15);
            versionLb.setHorizontalAlignment(SwingConstants.LEFT);
            versionPanel.add(versionLb);

            autherLb = new JLabel("xxx");
            autherLb.setBounds(80, 70, 150, 15);
            autherLb.setHorizontalAlignment(SwingConstants.LEFT);
            versionPanel.add(autherLb);

            dateLb = new JLabel("xxx");
            dateLb.setBounds(80, 100, 150, 15);
            dateLb.setHorizontalAlignment(SwingConstants.LEFT);
            versionPanel.add(dateLb);
        }
        initVersionInfo();
    }

    /**
     * 初始化版本信息
     *
     * @author fgq 2017年11月25日 下午4:14:09
     */
    private void initVersionInfo() {
        String filePath = FileUtils.getVersionPropertiesFilePath();
        String version = PropertiesHandler.readPropertiesConfigByKey("version", filePath);
        String auther = PropertiesHandler.readPropertiesConfigByKey("auther", filePath);
        String date = PropertiesHandler.readPropertiesConfigByKey("date", filePath);
        versionLb.setText(version);
        autherLb.setText(auther);
        dateLb.setText(date);
    }
}
